package net.sky.oa.dao.docs.impl;

import java.util.ArrayList;
import java.util.List;

import net.sky.oa.dao.SkyBaseDaoImpl;
import net.sky.oa.dao.docs.DocFileUserDao;
import net.sky.oa.model.DocFileUser;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Repository;

import com.htsoft.core.web.paging.PagingBean;

@SuppressWarnings("unchecked")
@Repository
public class DocFileUserDaoImpl extends SkyBaseDaoImpl<DocFileUser> implements DocFileUserDao {
	
	public DocFileUserDaoImpl() {
		super(DocFileUser.class);
	}
	
	public List<DocFileUser>  findByIds(Long fileId,Long susrId,Long fusrId,Long rusrId,PagingBean pagingBean){
		StringBuilder hql = new StringBuilder("select df from DocFileUser df where 1=1");// 个人文档
		List list = new ArrayList();
		if(fileId!=-1){
			hql.append(" and df.file.id=?");
			list.add(fileId);
		}
		if(susrId!=-1){
			hql.append(" and df.susr.id=?");
			list.add(susrId);
		}
		if(fusrId!=-1){
			hql.append(" and df.fusr.id=?");
			list.add(fusrId);
		}
		if(rusrId!=-1){
			hql.append(" and df.rusr.id=?");
			list.add(rusrId);
		}
		hql.append(" order by df.sendtime desc");
		if(null!=pagingBean)
			return findByHql(hql.toString(), list.toArray(), pagingBean);
		else
			return findByHql(hql.toString(), list.toArray());
			
	}
	
	public List<DocFileUser>  findByParams(Long fileId,Long susrId,Long fusrId,Long rusrId,String fileName,String sendtime,PagingBean pagingBean){
		StringBuilder hql = new StringBuilder("from DocFileUser df where 1=1");// 查收文档
		List list = new ArrayList();
		if(fileId!=-1){
			hql.append(" and df.file.id=?");
			list.add(fileId);
		}
		if(susrId!=-1){
			hql.append(" and df.susr.id=?");
			list.add(susrId);
		}
		if(fusrId!=-1){
			hql.append(" and df.fusr.id=?");
			list.add(fusrId);
		}
		if(rusrId!=-1){
			hql.append(" and df.rusr.id=?");
			list.add(rusrId);
		}
		if(StringUtils.isNotBlank(fileName)){
			hql.append(" and df.file.fileName=?");
			list.add(fileName);
		}
		if(StringUtils.isNotBlank(sendtime)){
			hql.append(" and to_char(df.sendtime,'yyyy-MM-dd')=?");
			list.add(sendtime);
		}
		hql.append(" order by df.sendtime desc");
		return findByHql(hql.toString(), list.toArray(), pagingBean);
			
	}
}
